package cn.stronglink.asset.module.contract;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.IdWorker;

import cn.stronglink.asset.model.Contract;
import cn.stronglink.asset.module.contract.mapper.ContractMapper;
import cn.stronglink.asset.module.contract.vo.ContractNoSelectVo;
import cn.stronglink.asset.module.contract.vo.ContractVo;
import cn.stronglink.suite.core.util.WebUtil;

@Service
@Transactional(rollbackFor=Exception.class)
public class ContractService {

	@Autowired
	private ContractMapper contractMapper;
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page<ContractVo> queryList(Page<ContractVo> page, Map<String, Object> params) {
		page.setRecords(contractMapper.queryList(page,params));
		return page;
	}
	public void create(Contract contract) {
		Date date=new Date();
		contract.setId(IdWorker.getId());
		contract.setCreateBy(WebUtil.getCurrentUser());
		contract.setCreateTime(date);
		contractMapper.create(contract);
	}
	public void update(Contract contract) {
		Date date=new Date();
		contract.setUpdateBy(WebUtil.getCurrentUser());
		contract.setUpdateTime(date);
		contractMapper.update(contract);
	}
	public void deleteById(Long id) {
		List<Long> ids=new ArrayList<Long>();
		ids.add(id);
		this.deleteByIds(ids);
	}
	public void deleteByIds(List<Long> ids) {
		if(ids!=null&&ids.size()>0){
			contractMapper.deleteByIds(ids);
		}
	}
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Contract getContractInfo(Long id) {
		return contractMapper.getContractInfo(id);
	}
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Integer getIsExist(Contract contract) {
		return contractMapper.getIsExist(contract);
	}
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<ContractNoSelectVo> queryAllContractList() {
		return contractMapper.queryAllContractList();
	}

}
